package com.hxit.huaxiamelongarden.utils;

import java.util.Random;

/**
 * @ClassName NicknameGenerator
 * @Author 12694
 * @Date 2025/1/21 12:51
 * @Version 1.0
 **/
public class NicknameGenerator {
    // 用户名的长度范围
    private static final int MIN_LENGTH = 6;
    private static final int MAX_LENGTH = 12;

    // 可用字符集
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    // 随机数生成器
    private static final Random RANDOM = new Random();

    // 生成随机用户名
    public static String generateRandomUsername() {
        // 用户名长度随机在 MIN_LENGTH 和 MAX_LENGTH 之间
        int length = RANDOM.nextInt(MAX_LENGTH - MIN_LENGTH + 1) + MIN_LENGTH;
        StringBuilder username = new StringBuilder(length);

        // 从字符集中随机挑选字符来生成用户名
        for (int i = 0; i < length; i++) {
            int index = RANDOM.nextInt(CHARACTERS.length());
            username.append(CHARACTERS.charAt(index));
        }

        return username.toString();
    }
}
